﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLXuongCNTT.Object;
namespace QLXuongCNTT.DataLayers
{
    class dtlVTTB
    {
        ConnectDB conn;
        SqlCommand cmd;
        string error;

        public string Error
        {
            get { return error; }
            set { error = value; }
        }
        public dtlVTTB()
        {
            conn = new ConnectDB();
            error = "";
        }
        public void insertVTTB(objVTTB vattu)
        {
            error = "";
            string sql = "Insert into Vattu_Thietbi(tenvt,nuocsx,dvt,dongia,namsd,mota,soluong,loai,sophieu) values(N'";
            sql+=vattu.Tenvt+"','";
           
            sql+=vattu.Nuocsx+"N','";
            sql+=vattu.Dvt+"',";
            sql+=vattu.Dongia+",";
            sql+=vattu.Namsd+",'";
            sql+=vattu.Mota+"',";
            sql+=vattu.Soluong+",'";
            
            sql+=vattu.Loai+"','";
            sql += vattu.Phieunhap + "')";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.Executive(cmd);
            error = conn.Error;
        }
        public DataTable Get_VatTu_ThietBi(objVTTB vt)
        {
            error = "";
            string sql = "select * from VATTU_THIETBI where SOPHIEU='" + vt.Phieunhap + "'";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.GetData(cmd);
            error = conn.Error;
            return conn;

        }
        public void DeleteVT(string pn)
        {
            error = "";
            string sql = "Delete from VATTU_THIETBI where SOPHIEU ='" + pn + "'";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.Executive(cmd);
            error = conn.Error;
        }
        public DataRow NewRow()
        {
            return conn.NewRow();
        }
        public void Addrow(DataRow row)
        {
            conn.Rows.Add(row);
        }
        public bool Save()
        {
            return (conn.Executive() > 0);
        } 
    }
}
